﻿using System;
using eLibrary.Environment;
using eLoop;

namespace eNets.CBK.Session;

static class ThreadSchedulerAllotter
{
    static ThreadSchedulerAllotter()
    {
        if (OS.IsWindows())
            SktAllotter = new DefaultThreadSchedulerAllotter(Environment.ProcessorCount, false);
        else
            SktAllotter = new InlineSchedulerAllotter();

        BufAllotter = new DefaultThreadSchedulerAllotter(Environment.ProcessorCount, false);
    }

    public static ADefaultAllotter SktAllotter
    {
        get;
    }

    public static ADefaultAllotter BufAllotter
    {
        get;
    }

    sealed class InlineSchedulerAllotter : ADefaultAllotter
    {
        public InlineSchedulerAllotter()
        {
            this.scheduler = Scheduler.Inline;
        }
        
        protected override ITaskScheduler[] Schedulers
        {
            get { throw new NotImplementedException(); }
        }
        

        private ITaskScheduler scheduler;

        public new int Count
        {
            get { return 1; }
        }

        public new ITaskScheduler Next()
        {
            return this.scheduler;
        }

        public new void Shutdown()
        {
        }
    }
    
}



